package com.hyfrogx.modules.job.task;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hyfrogx.common.utils.SpringContextUtils;
import com.hyfrogx.modules.app.utils.FrogConstant;
import com.hyfrogx.modules.job.entity.HyAdJobEntity;
import com.hyfrogx.modules.job.service.HyAdJobService;
import com.hyfrogx.modules.manage.entity.HyAdEntity;
import com.hyfrogx.modules.manage.service.HyAdService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @version 1.0.0
 * @Author: lfh
 * @Date: 2019/10/18 15:12
 * @Company 汉咏科技
 * 广告定时任务
 */
@Slf4j
@Component("AdTask")
public class AdTask {

    /**
     * Bean名称和方法名称
     */
    public static final String BEANNAME="AdTask";
    public static final String METHODNAME="ReleaseAd";
    @Autowired
    private HyAdService hyAdService;

    public void  ReleaseAd(String params)
    {
        log.info("广告上架任务START");
        Integer id = Integer.parseInt(params);
        HyAdEntity hyAdEntity = new HyAdEntity();
        hyAdEntity.setId(id);
        //设置广告状态为上架
        hyAdEntity.setStatus(FrogConstant.AdStatus.HAVING.getValue());
        //设置上架时间
        hyAdEntity.setReleaseDate(new Date());
        hyAdService.updateById(hyAdEntity);
        // 获取spring bean,执行后更改状态为废弃
        HyAdJobService hyAdJobService = (HyAdJobService) SpringContextUtils.getBean("hyAdJobService");
        HyAdJobEntity hyAdJobEntity = new HyAdJobEntity();
        hyAdJobEntity.setStatus(FrogConstant.AdJobStatus.NOUSING.getValue());
        hyAdJobService.update(hyAdJobEntity,new QueryWrapper<HyAdJobEntity>().eq("params",params));
        log.info("广告上架任务OVER");
    }

}
